package com.biz.ssm.controller.base;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.io.*;


public class BaseController {

	protected Logger logger = LoggerFactory.getLogger(getClass());

	/**
	 * Excel导出
	 * @param response
	 * @param infile
	 * @param downloadFile
	 * @throws Exception
	 */
	protected void exportFile(HttpServletResponse response, String infile, String downloadFile) throws Exception{
		File inFile = new File(infile);
		InputStream ins = new BufferedInputStream(new FileInputStream(inFile));
		byte[] buffer = new byte[ins.available()];
		ins.read(buffer);
		ins.close();
		response.reset();
		response.setCharacterEncoding("utf-8");
		response.addHeader("Content-Disposition", "attachment;filename="+ new String(downloadFile.getBytes("UTF-8"), "iso-8859-1"));
		response.addHeader("Content-Length", "" + inFile.length());
		OutputStream ous = new BufferedOutputStream(response.getOutputStream());
		response.setContentType("application/octet-stream;charset=utf-8");
		ous.write(buffer);
		ous.flush();
		ous.close();
	}

}
